package cn.minhx.domain.trade.service.lock.factory;

import cn.minhx.domain.trade.moedel.entity.GroupBuyActivityEntity;
import cn.minhx.domain.trade.moedel.entity.TradeLockRuleCommandEntity;
import cn.minhx.domain.trade.moedel.entity.TradeLockRuleFilterBackEntity;
import cn.minhx.domain.trade.service.lock.filter.ActivityUsabilityRuleFilter;
import cn.minhx.domain.trade.service.lock.filter.UserTakeLimitRuleFilter;
import cn.minhx.types.design.link.multi.LinkArmory;
import cn.minhx.types.design.link.multi.chain.BusinessLinkedList;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

/**
 * 交易规则过滤工厂
 *
 * @author min
 */
@Slf4j
@Service
public class TradeLockRuleFilterFactory {

	@Bean("tradeRuleFilter")
	public BusinessLinkedList<TradeLockRuleCommandEntity, DynamicContext, TradeLockRuleFilterBackEntity> tradeRuleFilter(
			ActivityUsabilityRuleFilter activityUsabilityRuleFilter, UserTakeLimitRuleFilter userTakeLimitRuleFilter) {
		// 组装链
		LinkArmory<TradeLockRuleCommandEntity, TradeLockRuleFilterFactory.DynamicContext, TradeLockRuleFilterBackEntity> linkArmory = new LinkArmory<>(
				"交易规则过滤链", activityUsabilityRuleFilter, userTakeLimitRuleFilter);
		// 链对象
		return linkArmory.getLogicLink();
	}

	@Data
	@Builder
	@NoArgsConstructor
	@AllArgsConstructor
	public static class DynamicContext {

		private GroupBuyActivityEntity groupBuyActivity;
	}
}
